<?php
defined('JSJZJX')||exit('JSJZJX Denied');
class NodeModel extends Model{
	protected $table = "kq_node";
	protected $pk = "id";
	protected $fields = array('id','name','title','pid','status','level');
	protected $_valid = array(
                               array('name',1,"英文名必须存在","require"),
                               array('title',1,"中文名必须存在","require"),
		);

	/*
	*查询节点的中文名称
	**/
	public function nodelist(){
		$sql = "select id,title,level from ".$this->table." where level<>3";
		return $this->db->getAll($sql);
	}

	/*
	*获取所有权限结构
	**/
	public function getstructure($arr,$id='0'){
		$data = array();
		foreach ($arr as $v) {
			if($v['pid'] == $id){
				$data[] = $v;
				$data = array_merge($data,$this->getstructure($arr,$v['id']));
			}
		}
		return $data;
	}

	//查给定id下的子栏目
	public function getSon($id){
		$sql="select title,name from ".$this->table.' where pid='.$id;
		return $this->db->getAll($sql);
	}

	public function findAllBySort(){
		$sql='select * from '.$this->table." order by sort";
    	return $this->db->getAll($sql);
	}

}
?>